/* Copyright (c) 2008 Google Inc.
*  Copyright (c) 2009 Pierre Henri Kuate.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*     http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

namespace org.opensocial.client
{
    /// <summary>
    /// Lists all known OpenSocial providers and their OAuth endpoints.
    /// </summary>
    /// <author> Cassandra Doll
    /// </author>
    public class OpenSocialProvider
    {
        public static OpenSocialProvider ORKUT = new OpenSocialProvider(null,
            null,
            null,
            "http://www.orkut.com/social/rest",
            "http://www.orkut.com/social/rpc", "Orkut", true);

        public static OpenSocialProvider ORKUT_SANDBOX = new OpenSocialProvider(null,
            null,
            null,
            "http://sandbox.orkut.com/social/rest",
            "http://sandbox.orkut.com/social/rpc", "Orkut Sandbox", true);

        public static OpenSocialProvider MYSPACE = new OpenSocialProvider("http://api.myspace.com/request_token",
            "http://api.myspace.com/authorize",
            "http://api.myspace.com/access_token",
            "http://api.myspace.com/v2",
            null, "MySpace", true);

        public static OpenSocialProvider HI5 = new OpenSocialProvider("https://api.hi5.com/oauth/requestToken",
            "https://login.hi5.com/oauth/authorize",
            "https://api.hi5.com/oauth/accessToken",
            "http://api.hi5.com/social/rest",
            "http://api.hi5.com/social/rpc", "Hi5", true);

        public static OpenSocialProvider HI5_SANDBOX = new OpenSocialProvider("https://api.hi5.com/oauth/requestToken",
            "https://login.hi5.com/oauth/authorize",
            "https://api.hi5.com/oauth/accessToken",
            "http://sandbox.hi5.com/social/rest",
            "http://sandbox.hi5.com/social/rpc", "Hi5 Sandbox", true);

        public static OpenSocialProvider PLAXO = new OpenSocialProvider("http://www.plaxo.com/oauth/request",
            "http://www.plaxo.com/oauth/authorize",
            "http://www.plaxo.com/oauth/activate",
            "http://www.plaxo.com/pdata/contacts",
            null, "Plaxo", false);

        public static OpenSocialProvider NETLOG = new OpenSocialProvider("http://en.netlog.com/oauth/request_token",
            "http://en.netlog.com/oauth/authorize",
            "http://en.netlog.com/oauth/access_token",
            "http://en.api.netlog.com/opensocial/social/rest",
            "http://en.api.netlog.com/opensocial/social/rpc", "Netlog", true);

        public static OpenSocialProvider GOOGLE = new OpenSocialProvider("https://www.google.com/accounts/OAuthGetRequestToken",
            "https://www.google.com/accounts/OAuthAuthorizeToken",
            "https://www.google.com/accounts/OAuthGetAccessToken",
            "http://sandbox.gmodules.com/api",
            null, "Google", true,
            "scope", "http://sandbox.gmodules.com/api/people");

        public static OpenSocialProvider PARTUZA = new OpenSocialProvider("http://www.partuza.nl/oauth/request_token",
            "http://www.partuza.nl/oauth/authorize",
            "http://www.partuza.nl/oauth/access_token",
            "http://modules.partuza.nl/social/rest",
            null, "Partuza", true);


        /// <summary>
        // Note: The SHINDIG provider uses a local OAuth provider. To get this local
        // OAuth provider running on port 9090, do the following:
        // 1) Download and launch example service provider from oauth.net:
        //    a) svn co http://oauth.googlecode.com/svn/code/java java
        //    b) cd java/example/oauth-provider
        //    c) mvn jetty:run-war
        // 2) If your OAuth provider is not running on port 9090 or your Shindig
        //    instance is not running on port 8080, edit the port numbers below.
        /// </summary>
        public static OpenSocialProvider Shindig = new OpenSocialProvider("http://localhost:9090/oauth-provider/request_token",
            "http://localhost:9090/oauth-provider/authorize",
            "http://localhost:9090/oauth-provider/access_token",
            "http://localhost:8080/social/rest/",
            "http://localhost:8080/social/rpc/", "localhost", true);





        public readonly string requestTokenUrl;
        public readonly System.Collections.Generic.Dictionary<string, string> requestTokenParams = new System.Collections.Generic.Dictionary<string, string>();
        public readonly string authorizeUrl;
        public readonly string accessTokenUrl;
        public readonly string restEndpoint;
        public readonly string rpcEndpoint;
        public readonly string providerName;
        public readonly bool isOpenSocial;
        public readonly string contentType;


        public OpenSocialProvider(string requestTokenUrl, string authorizeUrl, string accessTokenUrl,
            string restEndpoint, string rpcEndpoint, string providerName, bool isOpenSocial)
        {
            this.requestTokenUrl = requestTokenUrl;
            this.authorizeUrl = authorizeUrl;
            this.accessTokenUrl = accessTokenUrl;
            this.restEndpoint = restEndpoint;
            this.rpcEndpoint = rpcEndpoint;
            this.providerName = providerName;
            this.isOpenSocial = isOpenSocial;
            this.contentType = "application/json";
        }

        public OpenSocialProvider(string requestTokenUrl, string authorizeUrl, string accessTokenUrl,
            string restEndpoint, string rpcEndpoint, string providerName, bool isOpenSocial,
            string firstRequestTokenParamKey, string firstRequestTokenParamValue)
            : this(requestTokenUrl, authorizeUrl, accessTokenUrl, restEndpoint, rpcEndpoint, providerName, isOpenSocial)
        {
            requestTokenParams.Add(firstRequestTokenParamKey, firstRequestTokenParamValue);
        }
    }
}